package com.handy.util;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Toolkit {

	private static Log log = LogFactory.getLog(Toolkit.class);

	/**
	 * 判断字符串是否为数字.
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isNumeric(String str) {
		if (null== str || "".equals(str)){
			return false;
		}
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		}
		return true;
	}

	/**
	 * 将全角符号替换为半角符号。
	 * 
	 * @param sMo
	 *            String 转换前字符串
	 * @return boolean 转换后字符串
	 * @说明
	 */
	public synchronized static String convertStr(String str) {
		String sReturn = str;
		if (sReturn == null)
			return sReturn;
		try {
			sReturn = sReturn.toUpperCase();
			sReturn = sReturn.replace('，', ',');
			sReturn = sReturn.replace('。', '.');
			sReturn = sReturn.replace('；', ';');
			sReturn = sReturn.replace('！', '!');
			sReturn = sReturn.replace('？', '?');
			sReturn = sReturn.replace('：', ':');
			sReturn = sReturn.replace('"', '＂');
			sReturn = sReturn.replace('“', '＂');
			sReturn = sReturn.replace('”', '＂');
			sReturn = sReturn.replace('‘', '\'');
			sReturn = sReturn.replace('’', '\'');
			sReturn = sReturn.replace('，', ',');
			sReturn = sReturn.replace('０', '0');
			sReturn = sReturn.replace('１', '1');
			sReturn = sReturn.replace('２', '2');
			sReturn = sReturn.replace('３', '3');
			sReturn = sReturn.replace('４', '4');
			sReturn = sReturn.replace('５', '5');
			sReturn = sReturn.replace('６', '6');
			sReturn = sReturn.replace('７', '7');
			sReturn = sReturn.replace('８', '8');
			sReturn = sReturn.replace('９', '9');
		} catch (Exception e) {
			log.error(e.getMessage());
			return str;
		}
		return sReturn;
	}

}
